import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:keep_account/vm/add_work_records_controller.dart';

class AddWorkRecords extends StatefulWidget {
  const AddWorkRecords({super.key});
  @override
  State<StatefulWidget> createState() => _AddWorkRecordsState();

}

class _AddWorkRecordsState extends State<AddWorkRecords> {

  late final AddWorkRecordsController _controller = Get.put(AddWorkRecordsController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(leading: IconButton(
        onPressed: () {
          Get.back();
        },
        icon: const Icon(Icons.arrow_back,color: Colors.blue,),),title: const Text("工作记录"),),
      body: SingleChildScrollView(
        padding: const EdgeInsets.only(left: 15,right: 15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              margin: const EdgeInsets.only(top: 20),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(
                      width: double.infinity,
                      margin: const EdgeInsets.only(top: 15),
                      child: ListTile(
                        leading: Icon(Icons.calendar_month_rounded,color: Theme.of(context).colorScheme.primary,),
                        title: Obx(() => Text(_controller.workDate.value,style: const TextStyle(fontSize: 28,fontWeight: FontWeight.w500),)),
                        subtitle: const Text("点击可选择时间"),
                        titleAlignment: ListTileTitleAlignment.center,
                        onTap: (){
                          showChooseDateDialog();
                        },
                      )
                  ),
                  Container(
                    margin: const EdgeInsets.only(top: 20,left: 15,right: 15),
                    child: TextField(
                      textAlign: TextAlign.center,
                      controller: _controller.productQuantityController,
                      style: const TextStyle(fontSize: 20),
                      decoration: InputDecoration(
                          labelText: "产品数量",
                          hintText: "请输入产品数量",
                          hintStyle: const TextStyle(fontSize: 20),
                          border: UnderlineInputBorder(
                            borderSide: BorderSide(width: .1,color: Theme.of(context).colorScheme.primary)
                          ),
                          labelStyle: const TextStyle(fontSize: 20)
                      ),
                    ),
                  ),
                  Container(
                    margin: const EdgeInsets.only(top: 10,left: 15,right: 15),
                    child: TextField(
                      textAlign: TextAlign.center,
                      controller: _controller.productPriceController,
                      style: const TextStyle(fontSize: 20),
                      decoration: const InputDecoration(
                          labelText: "产品单价",
                          hintText: "请输入产品单价",
                          hintStyle: TextStyle(fontSize: 20),
                          border: UnderlineInputBorder(),
                          labelStyle: TextStyle(fontSize: 20)
                      ),
                    ),
                  ),
                  Container(
                    margin: const EdgeInsets.only(top: 10,left: 15,right: 15),
                    child: TextField(
                      textAlign: TextAlign.center,
                      controller: _controller.teamSizeController,
                      style: const TextStyle(fontSize: 20),
                      decoration: const InputDecoration(
                          labelText: "团队人数",
                          hintText: "请输入团队人数",
                          hintStyle: TextStyle(fontSize: 20),
                          border: UnderlineInputBorder(),
                          labelStyle: TextStyle(fontSize: 20)
                      ),
                    ),
                  ),
                  Container(
                    margin: const EdgeInsets.only(top: 60,left: 10,right: 10),
                    child: SizedBox(
                      width: double.infinity,
                      height: 55,
                      child: ElevatedButton(
                          onPressed: (){_controller.submitWorkRecord();},
                          child: const Text("提交工作记录",style: TextStyle(fontSize: 20),)
                      ),
                    ),
                  )
                ],
              ),
            ),

          ],
        ),
      ),
    );
  }

  void showChooseDateDialog() async {
    var time = await showDatePicker(
      context: context,
      initialEntryMode: DatePickerEntryMode.calendarOnly,
      initialDate: DateTime.now(),
      firstDate: DateTime(2010),
      lastDate: DateTime.now(),
    );
    if (time != null){
      _controller.workDate.value = "${time.year.toString()}-${time.month.toString().padLeft(2,'0')}-${time.day.toString().padLeft(2,'0')}";
    }

  }

}